﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using LybrixNursingCommon;
using LybrixNursingCRMDesktop.FrameWork;
namespace LybrixNursingCRMDesktop
{
    /// <summary>
    /// Interaction logic for agents.xaml
    /// </summary>
    public partial class agents : Page
    {
        private NursingDBContainer _entities;
        private agent currentAgent = null;
        public agents()
        {
            InitializeComponent();
            _entities = Repository.Entities;
            PerformSearch();
        }

        private void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            PerformSearch();
        }


        public void PerformSearch()
        {
            IQueryable<agent> agents = null;
            agents = (from x in _entities.agents select x);
            if (agentId.GotValue)
                agents = agents.Where(DynamicExpressions.GetWhereCond<agent>(agentId.FieldID, "Contains", agentId.Value));





            agentsListView.ItemsSource = agents;
        }

        private void ClearButton_Click(object sender, RoutedEventArgs e)
        {

        }

        private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
        {
            NavigationCenter.ShowDetailPage(currentAgent, NavigationTarget.AgentDetailsPage, this);
            e.Handled = true;
        }

        private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var dep = (DependencyObject)e.OriginalSource;
            while ((dep != null) && !(dep is ListViewItem))
            {
                dep = VisualTreeHelper.GetParent(dep);
            }
            if (dep == null)
                return;
            currentAgent = (agent)agentsListView.ItemContainerGenerator.ItemFromContainer(dep);
        }



        private void GridViewColumnHeaderClickedHandler(object sender, RoutedEventArgs e)
        {

        }
    }
}
